package ru.ibrae.mchs.radiation.common.excelEntities;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class ExcelRajon {

    private String name;
    private String sortFactor;
    private ArrayList<ExcelGSPos> excelGSPoses = new ArrayList<ExcelGSPos>();
    private ArrayList<ExcelGeoobject> excelGeoobjects = new ArrayList<ExcelGeoobject>();

    public ExcelRajon(String name, String sortFactor) {
        this.name = name;
        this.sortFactor = sortFactor;
    }

    public ArrayList<ExcelGSPos> getExcelGSPos() {
        return excelGSPoses;
    }

    public ArrayList<ExcelGeoobject> getExcelGeoobject() {
        return excelGeoobjects;
    }

    public String getName() {
        return name;
    }

    public String getSortFactor() {
        return sortFactor;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof ExcelRajon) {
            ExcelRajon excelRajon = (ExcelRajon) obj;
            if (this.getName().equals(excelRajon.getName())) {
                return true;
            } else {
                return false;
            }
        }
        return false;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 47 * hash + (this.name != null ? this.name.hashCode() : 0);
        hash = 47 * hash + (this.sortFactor != null ? this.sortFactor.hashCode() : 0);
        return hash;
    }

    public void doDeepSort() {
        Collections.sort(excelGSPoses, new Comparator<ExcelGSPos>() {

            @Override
            public int compare(ExcelGSPos o1, ExcelGSPos o2) {
                return o1.getSortFactor().compareToIgnoreCase(o2.getSortFactor());
            }
        });
        for (ExcelGSPos excelGSPos : excelGSPoses) {
            excelGSPos.doSorting();
        }
        Collections.sort(excelGeoobjects, new Comparator<ExcelGeoobject>() {

            @Override
            public int compare(ExcelGeoobject o1, ExcelGeoobject o2) {
                return o1.getName().compareToIgnoreCase(o2.getName());
            }
        });
    }
}
